<?
session_start();
include("includes/session.php");
$contract_sql = mysql_query("SELECT * FROM `contract` ORDER BY `id` DESC LIMIT 5");
while($contract_rs = mysql_fetch_object($contract_sql)){
	$product_sql = mysql_query("SELECT * FROM `product` WHERE `cid` = '$contract_rs->id'");
	$total_amount = 0;
	while($product_rs = mysql_fetch_object($product_sql)){
		$total_amount = $total_amount + ($product_rs->quantity * $product_rs->price * 11 / 10);
	}
	$status = contract_status($contract_rs->status);
	$status_class = contract_status_class($contract_rs->status);
	$last5contract .= '~>'.$contract_rs->name.'~>'.$contract_rs->tax.'~>'.$contract_rs->contract.'~>'.number_format($total_amount).'~>'.$status.'~>'.$status_class;
}
$today = strtotime(today_str()) - 1;
$tomorrow = strtotime(tomorrow_str()) + 1;
$event_sql = mysql_query("SELECT * FROM `event` WHERE `start` > '$today' AND `start` < '$tomorrow' ORDER BY `start` ASC");
while($event_rs = mysql_fetch_object($event_sql)){
	$event_today .= $event_today.'~>'.$event_rs->id.'~>'.$event_rs->title.'~>'.$event_rs->status;
}
$last5contract = arrchunk($last5contract, 6);
$event_today = arrchunk($event_today, 3);
$itt->assign("last5contract", $last5contract);
$itt->assign("is_event_today", mysql_num_rows($event_sql));
$itt->assign("event_today", $event_today);
$itt->assign("tittle", "Bảng điều khiển");
$itt->display('templates/main.tpl');
?>